package come.niit.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class HiveUtil {
    static final String DRIVER = "org.apache.hive.jdbc.HiveDriver";
    static final String URL = "jdbc:hive2://192.168.226.128:10000/kq";
    static final String USER = "root";
    static final String PASSWORD = "root";
    static Connection conn = null;
    static PreparedStatement ps = null;
    static ResultSet rs = null;
    static {
        try {
            Class.forName(DRIVER);
        }catch (Exception e){
            e.printStackTrace();
        }

    }

    public static ResultSet getRS(String sql){
        try {
            conn = DriverManager.getConnection(URL,USER,PASSWORD);
            ps = conn.prepareStatement(sql);
            rs = ps.executeQuery();
        }catch (Exception e){
            e.printStackTrace();
        }
        return rs;
    }

    public static void close(){
        try {
            if(rs != null ) rs.close();
            if(ps != null ) ps.close();
            if(conn != null ) conn.close();
        }catch (Exception e){
            e.printStackTrace();
        }
    }

}
